#ifndef _LOG_H_
#define _LOG_H_

#include <stdarg.h>
#include <string.h>
#include <stdint.h>

#include "log_def.h"
#include "log_ringbuff.h"

#ifdef __cplusplus
extern "C" {
#endif

struct log
{
    uint8_t init_ok;
    uint8_t early_init_ok;

    /* log buffer */
    char *log_buff;
    void *data_structure_ptr;

    /* filter level */
    uint32_t level;

    /* Synchronous  notification callback */
    void (*log_callback)(const char *log_buf, uint32_t log_len);
    /* Asynchronous notification callback */
    void (*async_callback)(void);
};

#define LOG_A(...)                      log_a(LOG_TAG, __VA_ARGS__)
#define LOG_E(...)                      log_e(LOG_TAG, __VA_ARGS__)
#define LOG_W(...)                      log_w(LOG_TAG, __VA_ARGS__)
#define LOG_I(...)                      log_i(LOG_TAG, __VA_ARGS__)
#define LOG_D(...)                      log_d(LOG_TAG, __VA_ARGS__)

void log_voutput(uint32_t level, const char *tag, const char *format, va_list args);
void log_output(uint32_t level, const char *tag, const char *format, ...);

int log_early_init(void (*log_callback)(const char *log_buf, uint32_t log_len));
int log_init(void (*async_callback)(void));
int log_deinit(void);
int log_global_level_set(uint32_t level);
uint32_t log_data_len(void);
uint32_t log_do_output(const char *log_buf, uint32_t log_len);
uint32_t log_data_get(char *ptr, uint32_t length);

void log_unregister_async_callback(void);
#ifdef __cplusplus
}
#endif

#endif /* _LOG_H_ */

